import asyncio
import os

import semantic_kernel as sk
from semantic_kernel.functions import KernelArguments, kernel_function


async def run_function(*args):
   return await kernel.invoke(*args)

class MyPluginClass:
    @kernel_function(
        description="执行本地函数",
        name="query_database"
    )
    def MyNativeFunction(self,arg1,arg2):
        print(f"call function MyNativeFunction({arg1}+{arg2}),{arg1} + {arg2}={arg1 + arg2}")
        pass

if __name__=='__main__':
   os.environ["OPENAI_API_KEY"] = os.environ["OPENAI_API_KEY_ZHIHU"]
   os.environ["OPENAI_BASE_URL"] = os.environ["OPENAI_API_BASE_ZHIHU"]

   kernel = sk.Kernel()
   #注册 function
   myPlugin = kernel.add_plugin(MyPluginClass(),"MyPluginClass")
   result = asyncio.run(run_function(myPlugin["query_database"], KernelArguments(arg1=10,arg2=20)))
   print(result)